/**
 * Created by IAN on 2016/10/14.
 */
$(function () {
    var eid = GetQueryString("eid");
    //加载分类列表
    var selSort = $.Params.create();
    selSort.ajax(getIP()+"metSort/getMetSorts",function(data){
        if(data.success){
            var html = "<option value='0'>请选择分类</option>";
            $.each(data.result,function(i,val) {
                html += "<option value='" + val.id + "'>" + val.sortTitle + "</option>";
            })
            $("#metSortId").html(html);
        }
    })
    //根据点播的id显示点播内容
    var selVideo = $.Params.create();
    selVideo.addParams("id",eid);
    selVideo.ajax(getIP()+"metVideo/getMetVideos",function(data){
        if(data.success){
            var val = data.result[0];
            var src = "../../img/"+val.picUrl;
            $("#loadImg").attr('src', src);
            $("#title").val(val.title);
            $("#url").val(val.url);
            $("#metSortId").val(val.metSortId);

        }
    })

    //添加信息
    $("#eid").val(eid);
    $("#addData").on("click",function(){
        var picUrl = $("#picUrl").val();
        var title = $("#title").val();
        var url = $("#url").val();
        var metSortId = $("#metSortId").val();


        if(title == ""){
            alert("请输入播标题！");
            return false;
        }
        if(url == ""){
            alert("请输入点播链接！");
            return false;
        }
        if(metSortId == "0"){
            alert("请选择分类！");
            return false;
        }else{
            $("#metSortTitle").val($("#metSortId").find("option:selected").text());
        }
        $("#addForm").attr("action",getIP()+"metVideo/updateMetVideoImg");
        $("#addForm").submit();
    })

    //取消修改信息
    $("#cancelAdd").on("click",function() {
        history.back(-1);
    })

    //实时预览图片
    $("#picUrl").on("change", function(e){
        var src, url = window.URL || window.webkitURL || window.mozURL, files = e.target.files;
        for (var i = 0, len = files.length; i < len; ++i) {
            var file = files[i];

            if (url) {
                src = url.createObjectURL(file);
            } else {
                src = e.target.result;
            }

            $("#loadImg").attr('src', src);
        }
    });
});